{include file="common/head"/} 
<div class="admin-main">
    <fieldset class="layui-elem-field layui-field-title"><legend>财务结算</legend></fieldset>
     <div class="demoTable layui-form"> 
            <div class="layui-inline">
                <select id="shopid" name="shopid" ng-model="field.shopid" lay-filter="shopid" lay-verify="required">
                    <option value="">请选择所属商户</option>
                    {volist name="shoplist" id="vo"}<option value="{$vo.id}">{$vo.name}</option>  {/volist}
                </select> 
            </div> 
            <div class="layui-inline">
                <select id="agentid" name="agentid" ng-model="field.agentid" lay-filter="agentid" lay-verify="required">
                    <option value="">请选择所属代理</option>
                    {volist name="agentlist" id="va"}<option value="{$va.id}">{$va.username}</option>  {/volist}
                </select> 
            </div> 
            <div class="layui-inline">
                <select id="userid" name="shopid" ng-model="field.userid" lay-filter="userid" lay-verify="required">
                    <option value="">请选择所属码商</option>
                    {volist name="userlist" id="vu"}<option value="{$vu.id}">{$vu.username}</option>  {/volist}
                </select> 
            </div> 
            <div class="layui-inline"> 
                <input type="text" id="timess" name="timess" class="layui-input" placeholder="选择日期" style="width: 300px"> 
            </div>
            <div class="layui-inline">
                <select id="status" name="shopid" ng-model="field.status" lay-filter="status" lay-verify="required">
                    <option value="">请选择审核状态</option>
                    <option value="1">待审核</option>
                    <option value="2">审核通过</option>
                </select> 
            </div>
            <button class="layui-btn layui-btn-primary" id="search">搜索</button> 
            <button class="layui-btn layui-btn-primary" id="total">统计</button>   
        </div>
	<div class="layui-clear"></div>
    <table class="layui-table layui-hide" id="total" lay-filter="totals"></table> 
    <table class="layui-table layui-hide" id="orderlist" lay-filter="listss"></table>
</div>    
<script src="/static/plugins/layui/layui.js"></script> 
<script type="text/html" id="action">
    {{# if (d.status == '<span class="red">待审核</span>') { }}  
        <div class="layui-btn layui-btn-normal layui-btn-xs" lay-event="passit">处理</div>
    {{# } else if(d.status == '<span class="green">审核通过</span>') { }}  
        <div class="layui-btn layui-btn-disabled layui-btn-xs">已处理</div>
    {{# } else { }}  
        <div class="layui-btn layui-btn-disabled layui-btn-xs">未知类型</div>        
    {{# } }}  
</script>
<script type="text/html" id="paymentpic">
    {{# if(d.payment_img){ }}<img src="{{d.payment_img}}" width="200px" class="layui-upload-img" onclick="previewImg(this)" >{{# } }}
</script> 
<script>
    layui.use(['layer','table','form','laydate'], function() {
        var table = layui.table,form = layui.form, layer = layui.layer,laydate = layui.laydate;;
        $ = layui.jquery;
        laydate.render({
            elem: '#timess',range: true,type: 'datetime'
        });
        tableIn = table.render({
            id: 'listss',
            elem: '#orderlist', 
            url: '{:url("settle")}',
            method: 'post', 
            page: true,
            cols: [[ 
                {field: 'id', title: 'ID',align: 'center', width:50, fixed: true},
                {field: 'type', title: '结算类型',align: 'center', width: 80, fixed: true},
                {field: 'paytype', title: '结算方式',align: 'center', width: 80, fixed: true}, 
                {field: 'typename', title: '结算对象',align: 'center', width: 100, fixed: true},
                {field: 'payname', title: '收款详情',align: 'center', width: 200},  
                {field: 'user', title: '联系人',align: 'center', width: 100}, 
                {field: 'payno', title: '收款账号',align: 'center', width: 150}, 
                {field: 'cash', title: '金额',align: 'center', width: 100}, 
                {field: 'mobile', title: '联系电话',align: 'center', width: 120}, 
                {field: 'idcard', title: '身份证',align: 'center', width: 150}, 
                {field: 'status', title: '审核状态',align: 'center', width: 100},
                {field: 'addtime', title: '提交时间',align: 'center', width: 160}, 
                {field: 'endtime', title: '审核通过时间',align: 'center', width: 160},
                {field: 'payment_img', title: '收款码',align: 'center', width: 160,templet: '#paymentpic'}, 
                {title: '操作', width: 80,align: 'center', fixed:'right',toolbar: '#action'},
            ]],
            limit: 60 //每页默认显示的数量
        });
        //搜索
        $('#search').on('click', function() {
            var shopid = $('#shopid').val();
            var agentid = $('#agentid').val();
            var userid = $('#userid').val();
            var timess = $('#timess').val();
            var status = $('#status').val();
            if($.trim(shopid)==='' && $.trim(agentid)==='' && $.trim(userid)==='' && $.trim(timess)==='' && $.trim(status)==='') {
                layer.msg('请输入查询条件！',{icon:0});
                return;
            }else{
                tableIn.reload({ page: {page: 1},where: {shopid: shopid,agentid: agentid,userid: userid,timess: timess,status: status}});
            } 
        }); 
        //统计
         totalIn = table.render({ 
            id: '#totals',      
            elem: '#total',
            // toolbar: '#totals',
            url: '{:url("total")}',
            method: 'post', 
            // page: true,
            cols: [[ 
                {field: 'balance', title: '<span style="color: green;">平台余额</span>',align: 'center', width:130, fixed: true},
                {field: 'shop_yes', title: '<span style="color: green;">商户已结算总额</span>',align: 'center', width:130, fixed: true},
                {field: 'shop_cash', title: '<span style="color: green;">商户提现总额</span>',align: 'center', width:130, fixed: true},
                {field: 'shop_balance', title: '<span style="color: green;">商户余额</span>',align: 'center', width:130, fixed: true},
                {field: 'agent_yes', title: '<span style="color: green;">代理手续费总额</span>',align: 'center', width:130, fixed: true},
                {field: 'agent_cash', title: '<span style="color: green;">代理提现总额</span>',align: 'center', width:130, fixed: true},
                {field: 'agent_balance', title: '<span style="color: green;">代理余额</span>',align: 'center', width:130, fixed: true},
                {field: 'user_yes', title: '<span style="color: green;">码商手续费总额</span>',align: 'center', width:130, fixed: true},
                {field: 'user_cash', title: '<span style="color: green;">码商提现总额</span>',align: 'center', width:130, fixed: true},
                {field: 'user_balance', title: '<span style="color: green;">码商余额</span>',align: 'center', width:130, fixed: true},
            ]],
            // limit: 60 //每页默认显示的数量
        });  
        $('#total').on('click', function() {
            var shopid = $('#shopid').val();
            var agentid = $('#agentid').val();
            var userid = $('#userid').val();
            var timess = $('#timess').val();
            var status = $('#status').val();
            if($.trim(shopid)==='' && $.trim(agentid)==='' && $.trim(userid)==='' && $.trim(timess)==='' && $.trim(status)==='') {
                layer.msg('请输入搜索条件！',{icon:0});
                return;
            }else{
                totalIn.reload({where: {shopid: shopid,agentid: agentid,userid: userid,timess: timess,status: status}});
            } 
        });

        table.on('tool(listss)', function(obj) {
            var data = obj.data;
            if(obj.event === 'passit') {
            	var type=data.type; 
            	tipss='确定已将款项结算？';
                layer.confirm(tipss, function(index){ 
                    $.post("{:url('pass_settle')}",{id:data.id},function(res){
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1},function(){ 
                            	tableIn.reload();
                            });
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });  
    });

 function previewImg(obj) {
        var img = new Image();  
        img.src = obj.src;
        var imgHtml = "<img src='" + obj.src + "' width='500px' height='500px'/>";  
        //弹出层
        layer.open({  
            type: 1,  
            shade: 0.8,
            offset: 'auto',
            area: [500 + 'px',550+'px'],
            shadeClose:true,
            scrollbar: false,
            title: "图片预览", //不显示标题  
            content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响  
            cancel: function () {  
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });  
            }  
        }); 
    }
</script>
</body>
</html>